//
//  DTAlertView.m
//  SmartStore
//
//  Created by JianWei Chen on 16/7/5.
//  Copyright © 2016年 JianWei Chen. All rights reserved.
//

#import "DTAlertView.h"

@implementation UITextField (DTLeftPlaceholderView)

- (void)addLeftPlaceholderView {
    UIView * leftV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
    self.leftView = leftV;
    self.leftViewMode = UITextFieldViewModeAlways;
}

@end

#define AlertSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define AlertSCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define AlertSpace  50.f
#define CornerRadius 8.f
#define TextFont 13.f
#define NoticeTextFont 17.f
#define NoticeLabelSpace 10.f
#define ContentLabelSpace 10.f
#define AlertUpSpace 40.f
#define ContentMessageWidth (360 - 2*AlertSpace)
#define DefaultContentHeight 80.f
#define DefaultMaxContentHeight 180.f
#define DefaultBtnHeight 40.f
#define DefaultTextHeight 40.f
#define BtnColor [UIColor colorWithRed:78/255.f green:143/255.f blue:217/255.f alpha:1]
#define NoticeBGColor [UIColor colorWithRed:78/255.f green:143/255.f blue:217/255.f alpha:1]
#define TextFieldBGColor [UIColor colorWithRed:245/255.f green:245/255.f blue:245/255.f alpha:1]
#define TextContenColor [UIColor darkGrayColor]

@interface DTAlertView ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>

@property (nonatomic, strong) UIView *contentBackgroudView;
@property (strong, nonatomic) UIView *contentMessageView;
@property (strong, nonatomic) NSString *noticeString;
@property (strong, nonatomic) NSString *messageString;
@property (assign, nonatomic) DTAlertViewType alerViewType;
@property (assign, nonatomic) CGFloat noticeHeight;
@property (assign, nonatomic) CGFloat contentHeight;
@property (assign, nonatomic) CGFloat actionViewHeight;
@property (strong, nonatomic) UIView *noticeView;
@property (strong, nonatomic) UIView *messageShowView;
@property (strong, nonatomic) UIWindow *theWindow;
@property (strong, nonatomic) UILabel *noticeLabel;
@property (strong, nonatomic) UIView *actionView;
@property (strong, nonatomic) NSArray *actionNameArray;
@property (strong, nonatomic) NSArray *texFieldPlaceHolderArray;
@property (strong, nonatomic) NSArray *infoArray;
@property (strong, nonatomic) NSArray *selectArray;
@property (strong, nonatomic) NSMutableArray *dataSource;
@property (copy, nonatomic) DTAlertViewBlock currentBlock;
@property (copy, nonatomic) DTAlertViewTextFieldBlock currentTextBlock;
@property (copy, nonatomic) DTAlertViewSelectBlock currentSelectBlock;
@property (strong, nonatomic) UITableView *tableView;
@property (assign, nonatomic) int currentSelect;

@end

@implementation DTAlertView

+ (DTAlertView *)defaultService
{
    static DTAlertView *sz_object = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sz_object = [[DTAlertView alloc]init];
    });
    return sz_object;
}
- (void)showWithNotice:(NSString *)noticeString andSelectArray:(NSArray *)selectArray andActionNameArray:(NSArray *)actionNameArray andAlertViewBlock:(DTAlertViewSelectBlock)actionBlock
{
    [self setValueForNull];//置空
    
    self.noticeString = noticeString;
    self.actionNameArray = actionNameArray;
    self.selectArray = selectArray;
    self.currentSelectBlock = actionBlock;
    self.alerViewType = DTAlertViewType_Select;
    self.contentMessageView = nil;
    [self setMessageForShow];
}

- (void)showWithNotice:(NSString *)noticeString andMessage:(NSString *)messageString andActionNameArray:(NSArray *)actionNameArray andAlerViewBlock:(DTAlertViewBlock)actionBlock
{
    [self setValueForNull];//置空
    
    self.noticeString = noticeString;
    self.messageString = messageString;
    self.actionNameArray = actionNameArray;
    self.currentBlock = actionBlock;
    self.alerViewType = DTAlertViewType_Normal;
    self.contentMessageView = nil;
    [self setMessageForShow];
}

- (void)showWithNotice:(NSString *)noticeString andEditTextFieldArray:(NSArray *)texFieldPlaceHolder andActionNameArray:(NSArray *)actionNameArray andAlerViewBlock:(DTAlertViewTextFieldBlock)actionBlock
{
    [self setValueForNull];//置空
    
    self.noticeString = noticeString;
    self.actionNameArray = actionNameArray;
    self.texFieldPlaceHolderArray = texFieldPlaceHolder;
    self.currentTextBlock = actionBlock;
    self.alerViewType = DTAlertViewType_TextInput;
    self.contentMessageView = nil;
    [self setMessageForShow];
}

- (void)showWithNotice:(NSString *)noticeString andInfoArray:(NSArray *)infoArray andActionNameArray:(NSArray *)actionNameArray andAlertViewBlock:(DTAlertViewBlock)actionBlock
{
    [self setValueForNull];//置空
    
    self.noticeString = noticeString;
    self.actionNameArray = actionNameArray;
    self.infoArray = infoArray;
    self.currentBlock = actionBlock;
    self.alerViewType = DTAlertViewType_ShowInfo;
    self.contentMessageView = nil;
    [self setMessageForShow];
}
- (void)setValueForNull
{
    self.currentSelectBlock = nil;
    self.currentBlock = nil;
    self.currentTextBlock = nil;
    self.infoArray = nil;
    self.selectArray = nil;
    self.texFieldPlaceHolderArray = nil;
}

- (UIView *)contentBackgroudView
{
    if (!_contentBackgroudView) {
        _contentBackgroudView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, AlertSCREEN_WIDTH, AlertSCREEN_HEIGHT)];
        _contentBackgroudView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(setEndEditing)];
        tap.delegate = self;
        [_contentBackgroudView addGestureRecognizer:tap];
    }
    return _contentBackgroudView;
}

- (UIView *)contentMessageView
{
    if (!_contentMessageView) {
        _contentMessageView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ContentMessageWidth , self.noticeHeight + self.contentHeight + self.actionViewHeight)];
        _contentMessageView.backgroundColor = [UIColor whiteColor];
        _contentMessageView.layer.cornerRadius = CornerRadius;
        _contentMessageView.clipsToBounds = YES;
        _contentMessageView.layer.shadowColor = [UIColor blackColor].CGColor;
        _contentMessageView.layer.shadowRadius = 8.0f;
        _contentMessageView.layer.shadowOffset = CGSizeMake(0.0f, 2.0f);
        _contentMessageView.layer.shadowOpacity = 1.f;
        _contentMessageView.center = CGPointMake(AlertSCREEN_WIDTH/2, AlertSCREEN_HEIGHT/2 - AlertUpSpace);
    }
    return _contentMessageView;
}

- (void)setMessageForShow
{
    [self.contentBackgroudView addSubview:self.contentMessageView];
    [self.contentMessageView addSubview:self.noticeView];//添加提示信息栏
    [self.contentMessageView addSubview:self.messageShowView];
    [self.contentMessageView addSubview:self.actionView];
    
    [self.theWindow addSubview:self.contentBackgroudView];
}

- (UIView *)noticeView
{
    if (!_noticeView) {
        _noticeView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ContentMessageWidth, self.noticeHeight)];
        _noticeView.backgroundColor = NoticeBGColor;
        
        UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(NoticeLabelSpace, NoticeLabelSpace, CGRectGetWidth(_noticeView.frame) - 2*NoticeLabelSpace, CGRectGetHeight(_noticeView.frame) - 2*NoticeLabelSpace)];
        lable.textAlignment = NSTextAlignmentCenter;
        lable.textColor = [UIColor whiteColor];
        lable.font = [UIFont systemFontOfSize:NoticeTextFont];
        lable.text = self.noticeString;
        lable.numberOfLines = 0;
        self.noticeLabel = lable;
        [_noticeView addSubview:lable];
    }else{
        _noticeView.frame = CGRectMake(0, 0, ContentMessageWidth, self.noticeHeight);
        self.noticeLabel.frame = CGRectMake(NoticeLabelSpace, NoticeLabelSpace, CGRectGetWidth(_noticeView.frame) - 2*NoticeLabelSpace, CGRectGetHeight(_noticeView.frame) - 2*NoticeLabelSpace);
        self.noticeLabel.text = self.noticeString;
    }
    
    return _noticeView;
}

- (UIWindow *)theWindow
{
    return [UIApplication sharedApplication].keyWindow;
}
#pragma mark - 高度计算
- (CGFloat)noticeHeight
{
    CGFloat height = [self CountTheString:self.noticeString withTheStringFont:[UIFont systemFontOfSize:NoticeTextFont] andMaxSize:CGSizeMake(ContentMessageWidth - 2*ContentLabelSpace, 200)].size.height;
    return (height < 40)? 40.f:height;
}




- (CGRect)CountTheString:(NSString *)string withTheStringFont:(UIFont *)font andMaxSize:(CGSize )size
{
    return [string boundingRectWithSize:size
                                options:NSStringDrawingUsesLineFragmentOrigin
                             attributes:@{NSFontAttributeName:font}
                                context:nil];
}

- (CGFloat)contentHeight
{
    CGFloat height = 0;
    switch (self.alerViewType) {
        case DTAlertViewType_Normal:
        {
            height = [self CountTheString:self.messageString withTheStringFont:[UIFont systemFontOfSize:TextFont] andMaxSize:CGSizeMake(ContentMessageWidth - 2*ContentLabelSpace, 200)].size.height + 2*ContentLabelSpace;
            if (height < DefaultContentHeight) {
                height = DefaultContentHeight;
            }
        }
            break;
        case DTAlertViewType_TextInput:
        {
            height = self.texFieldPlaceHolderArray.count * (DefaultBtnHeight + ContentLabelSpace) +ContentLabelSpace;
        }
            break;
        case DTAlertViewType_ShowInfo:
        {
            for (int i = 0; i < self.infoArray.count ; i++) {
                NSDictionary *contentDic = self.infoArray[i];
                NSString *showString = [NSString stringWithFormat:@"%@：%@",contentDic[@"group"],contentDic[@"value"]];
                CGFloat currentHeight = [self CountTheString:showString withTheStringFont:[UIFont systemFontOfSize:TextFont] andMaxSize:CGSizeMake(ContentMessageWidth - 2*ContentLabelSpace, 200)].size.height;
                if (currentHeight < 20) {
                    currentHeight = 20;
                }
                height += (currentHeight + 20);
            }
            _tableView.scrollEnabled = NO;
            if (height < DefaultBtnHeight) {
                height = DefaultBtnHeight;
            }else if (height > DefaultMaxContentHeight){
                height = DefaultMaxContentHeight;
                _tableView.scrollEnabled = YES;
            }
        }
            break;
        case DTAlertViewType_Select:
        {
            for (int i = 0; i < self.selectArray.count ; i++) {
                NSString *showString = self.selectArray[i];
                CGFloat currentHeight = [self CountTheString:showString withTheStringFont:[UIFont systemFontOfSize:TextFont] andMaxSize:CGSizeMake(ContentMessageWidth - 2*ContentLabelSpace, 200)].size.height;
                if (currentHeight < 20) {
                    currentHeight = 20;
                }
                height += (currentHeight + 20);
            }
            _tableView.scrollEnabled = NO;
            if (height < DefaultBtnHeight) {
                height = DefaultBtnHeight;
            }else if (height > DefaultMaxContentHeight){
                height = DefaultMaxContentHeight;
                _tableView.scrollEnabled = YES;
            }
        }
            break;
            
        default:
            break;
    }
    return height;
}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(ContentLabelSpace, 0, ContentMessageWidth - 2*ContentLabelSpace, self.contentHeight) style:UITableViewStylePlain];
        _tableView.separatorInset = UIEdgeInsetsZero;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.scrollEnabled = NO;
        if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
            
            [_tableView setSeparatorInset:UIEdgeInsetsZero];
        }
        if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
            [_tableView setLayoutMargins:UIEdgeInsetsZero];
        }
    }
    return _tableView;
}

- (CGFloat)actionViewHeight
{
    if (self.actionNameArray.count <= 2) {
        return DefaultBtnHeight;
    }
    return DefaultBtnHeight *self.actionNameArray.count;
}
#pragma mark - 内容填充
- (UIView *)messageShowView
{
    if (!_messageShowView) {
        _messageShowView = [[UIView alloc]initWithFrame:CGRectMake(0, self.noticeHeight, ContentMessageWidth, self.contentHeight)];
        [self addLineView:_messageShowView];//画线
    }else{
        _messageShowView.frame = CGRectMake(0, self.noticeHeight, ContentMessageWidth, self.contentHeight);
        UIView *lineView = [_messageShowView viewWithTag:999];
        lineView.frame = CGRectMake(0, self.contentHeight - 1, ContentMessageWidth, 1);
        lineView.hidden = (self.alerViewType == DTAlertViewType_ShowInfo || self.alerViewType == DTAlertViewType_Select)?YES:NO;
        for (UIView *view in _messageShowView.subviews) {
            [view removeFromSuperview];
        }
    }
    
    switch (self.alerViewType) {
        case DTAlertViewType_Normal:
        {
            UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(ContentLabelSpace, ContentLabelSpace, CGRectGetWidth(_messageShowView.frame) - 2*ContentLabelSpace, CGRectGetHeight(_messageShowView.frame) - 2*ContentLabelSpace)];
            lable.textAlignment = NSTextAlignmentCenter;
            lable.textColor = TextContenColor;
            lable.font = [UIFont systemFontOfSize:TextFont];
            lable.text = self.messageString;
            lable.numberOfLines = 0;
            
            [_messageShowView addSubview:lable];
        }
            break;
        case DTAlertViewType_TextInput:
        {
            [self setTextFieldArrayView:_messageShowView];
        }
            break;
        case DTAlertViewType_ShowInfo:
        {
            [self setShowInfoView];
        }
            break;
        case DTAlertViewType_Select:
        {
            [self setSelectView];
        }
            
        default:
            break;
    }
    
    
    
    return _messageShowView;
}

- (void)addLineView:(UIView *)view
{
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, self.contentHeight - 1, ContentMessageWidth, 1)];
    lineView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.05];
    lineView.tag = 999;
    lineView.hidden = (self.alerViewType == DTAlertViewType_ShowInfo || self.alerViewType == DTAlertViewType_Select)?YES:NO;
    [view addSubview:lineView];
}


- (UIView *)actionView
{
    if (!_actionView) {
        _actionView = [[UIView alloc]init];
        _actionView.backgroundColor = [UIColor whiteColor];
    }
    
    for (UIView *view in _actionView.subviews) {
        [view removeFromSuperview];
    }
    
    [self setBtnForActionView];
    
    return _actionView;
}

- (void)setSelectView
{
    [self.tableView removeFromSuperview];
    [self.dataSource removeAllObjects];
    [self.dataSource addObjectsFromArray:self.selectArray];
    [_messageShowView addSubview:_tableView];
    [_messageShowView sendSubviewToBack:_tableView];
    [_tableView reloadData];
}

- (void)setShowInfoView
{
    [self.tableView removeFromSuperview];
    [self.dataSource removeAllObjects];
    for (NSDictionary *dic in self.infoArray) {
        [self.dataSource addObject:[NSString stringWithFormat:@"%@：%@",dic[@"group"],dic[@"value"]]];
    }
    [_messageShowView addSubview:_tableView];
    [_messageShowView sendSubviewToBack:_tableView];
    [_tableView reloadData];
}

- (void)setTextFieldArrayView:(UIView *)view
{
    for (int i = 0; i < self.texFieldPlaceHolderArray.count; i++) {
        UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(ContentLabelSpace, ContentLabelSpace + i*(ContentLabelSpace + DefaultBtnHeight), ContentMessageWidth - 2*ContentLabelSpace , DefaultBtnHeight)];
        textfield.layer.cornerRadius = 3;
        textfield.clipsToBounds = YES;
        NSDictionary *nameDic = self.texFieldPlaceHolderArray[i];
        textfield.placeholder = nameDic[@"name"];
        textfield.secureTextEntry = [nameDic[@"isPassword"]boolValue];
        textfield.font = [UIFont systemFontOfSize:TextFont];
        [textfield addLeftPlaceholderView];
        textfield.backgroundColor = TextFieldBGColor;
        textfield.textColor = TextContenColor;
        textfield.tag = 1+i;
        [view addSubview:textfield];
    }
}

- (void)setBtnForActionView
{
    if (self.actionNameArray.count == 1) {
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn setBackgroundImage:[UIImage imageNamed:@"bottom_bg_sel"] forState:UIControlStateHighlighted];
        btn.frame = CGRectMake(0, 0, ContentMessageWidth, DefaultBtnHeight);
        [btn setTitle:self.actionNameArray[0] forState:UIControlStateNormal];
        [btn setTitleColor:BtnColor forState:UIControlStateNormal];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:NoticeTextFont]];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 0;
        [_actionView addSubview:btn];
        _actionView.frame = CGRectMake(0, self.noticeHeight + self.contentHeight, ContentMessageWidth, self.actionViewHeight);
    }else if (self.actionNameArray.count == 2){
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn setBackgroundImage:[UIImage imageNamed:@"bottom_bg_sel"] forState:UIControlStateHighlighted];
        btn.frame = CGRectMake(0, 0, ContentMessageWidth/2, DefaultBtnHeight);
        [btn setTitle:self.actionNameArray[0] forState:UIControlStateNormal];
        [btn setTitleColor:BtnColor forState:UIControlStateNormal];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:NoticeTextFont]];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 0;
        [_actionView addSubview:btn];
        UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn1 setBackgroundImage:[UIImage imageNamed:@"bottom_bg_sel"] forState:UIControlStateHighlighted];
        btn1.frame = CGRectMake(ContentMessageWidth/2, 0, ContentMessageWidth/2, DefaultBtnHeight);
        [btn1 setTitle:self.actionNameArray[1] forState:UIControlStateNormal];
        [btn1 setTitleColor:BtnColor forState:UIControlStateNormal];
        [btn1.titleLabel setFont:[UIFont systemFontOfSize:NoticeTextFont]];
        [btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn1.tag = 1;
        [_actionView addSubview:btn1];
        _actionView.frame = CGRectMake(0, self.noticeHeight + self.contentHeight, ContentMessageWidth, self.actionViewHeight);
    }else{
        for (int i = 0 ; i < self.actionNameArray.count ; i ++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
            [btn setBackgroundImage:[UIImage imageNamed:@"bottom_bg_sel"] forState:UIControlStateHighlighted];
            btn.frame = CGRectMake(0, DefaultBtnHeight * i, ContentMessageWidth, DefaultBtnHeight);
            [btn setTitle:self.actionNameArray[i] forState:UIControlStateNormal];
            [btn setTitleColor:BtnColor forState:UIControlStateNormal];
            [btn.titleLabel setFont:[UIFont systemFontOfSize:NoticeTextFont]];
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            btn.tag = i;
            [_actionView addSubview:btn];
        }
        _actionView.frame = CGRectMake(0, self.noticeHeight + self.contentHeight, ContentMessageWidth, self.actionViewHeight);
    }
}

- (void)setEndEditing
{
    [self.theWindow endEditing:YES];
}

- (void)btnClick:(UIButton *)sender
{
    [self.contentBackgroudView removeFromSuperview];
    if (self.currentBlock) {
        self.currentBlock((int)sender.tag);
    }else if (self.currentTextBlock){
        NSMutableArray *textArray = [[NSMutableArray alloc]init];
        for (int i = 0; i < self.texFieldPlaceHolderArray.count ; i ++) {
            UITextField *text = [_messageShowView viewWithTag:i+1];
            if ([text isKindOfClass:[UITextField class]]) {
                [textArray addObject:text.text];
            }
        }
        self.currentTextBlock(textArray,(int)sender.tag);
    }else if (self.currentSelectBlock){
        self.currentSelectBlock(self.currentSelect,(int)sender.tag);
    }
}

- (NSMutableArray *)dataSource
{
    if (!_dataSource) {
        _dataSource = [[NSMutableArray alloc]init];
    }
    return _dataSource;
}

#pragma mark - tableView 代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    NSString *string = self.dataSource[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:TextFont];
    cell.textLabel.text = string;
    cell.imageView.image = (self.selectArray.count != 0 && indexPath.row == self.currentSelect)?[UIImage imageNamed:@"status_ok"]:nil;
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *string = self.dataSource[indexPath.row];
    
    return [self getCellHeight:string];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.selectArray.count != 0) {
        self.currentSelect = (int)indexPath.row;
        [tableView reloadData];
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (CGFloat)getCellHeight:(NSString *)string
{
    CGFloat height = 0;
    height = [self CountTheString:string withTheStringFont:[UIFont systemFontOfSize:TextFont] andMaxSize:CGSizeMake(ContentMessageWidth - 2*ContentLabelSpace, 200)].size.height;
    if (height < 20) {
        height = 20;
    }
    height = height + 20;
    
    if (height < DefaultBtnHeight) {
        height = DefaultBtnHeight;
    }
    return height;
}

#pragma mark - 手势代理
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    for (UIView* next = [touch.view superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isEqual:self.contentMessageView]) {
            return NO;
        }
    }
    
    return YES;
}
@end
